package com.sanchunhui.psc.ui.activity

import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.sanchunhui.psc.R
import com.sanchunhui.psc.presenter.SplashPresenter
import org.jetbrains.anko.startActivity


/**
 * @Author zyx
 * @Date 2021/4/19-11:29
 * @Dscribe 启动界面
 */
class SplashActivity : AppCompatActivity() {

    val presenter = SplashPresenter(this)

    companion object {
        val DELAY = 2000L // 延时2s
    }
    val handler by lazy {
        Handler()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        if ( presenter.isLoggedIn()) {
            onLoggedIn()
        } else {
            onNotLoggedIn()
        }

    }

    //延时2s,跳转到登陆界面
    fun onNotLoggedIn() {
        handler.postDelayed(object : Runnable {
            override fun run() {
                startActivity<LoginActivity>()
                finish()
            }
        }, DELAY)
    }

    //已登陆跳转到主界面
    fun onLoggedIn() {
        handler.postDelayed(object : Runnable {
            override fun run() {
                startActivity<MainActivity>()
                finish()
            }
        }, DELAY)
    }


}